<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="template/adminBase.xhtml">
    <ui:define name="adminContent">
        <h:form>
            <h:dataTable value="#{roomController.rooms}" var="room"
                         styleClass="cinemaTable"
                         headerClass="cinemaTableHeader"
                         rowClasses="cinemaTableOddRow,cinemaTableEvenRow">
                <h:column>
                    <f:facet name="header">Name</f:facet>
                    <h:inputText id="newName" label="Title" value="#{room.name}"
                                 size="10" rendered="#{roomController.canEdit.get(roomController.rooms.indexOf(room))}">
                        <f:validateLength minimum="2"/>
                    </h:inputText>
                    <h:outputText value="#{room.name}"
                                  rendered="#{not roomController.canEdit.get(roomController.rooms.indexOf(room))}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Edit</f:facet>
                    <h:commandButton class="adminButton" value="Edit"
                                     action="#{roomController.editRoom}"
                                     rendered="#{not roomController.canEdit.get(roomController.rooms.indexOf(room))}">
                        <f:setPropertyActionListener
                                target="#{roomController.room}" value="#{room}"/>
                    </h:commandButton>
                    <h:commandButton class="adminButton" value="Save"
                                     action="#{roomController.saveRoom}"
                                     rendered="#{roomController.canEdit.get(roomController.rooms.indexOf(room))}">
                        <f:setPropertyActionListener
                                target="#{roomController.room}" value="#{room}"/>
                    </h:commandButton>
                </h:column>
                <h:column>
                    <f:facet name="header">Delete</f:facet>
                    <h:commandButton class="adminButton" value="Delete"
                                     action="#{roomController.deleteRoom}">
                        <f:setPropertyActionListener
                                target="#{roomController.room}" value="#{room}"/>
                    </h:commandButton>
                </h:column>
            </h:dataTable>
            <h:message for="newName" style="color:red"/>
        </h:form>
        <h:form>

            <h3>Add Room</h3>
            <table>
                <tr>
                    <td>Name:</td>
                    <td>
                        <h:inputText id="nameInput" label="Name" class="inputText"
                                     size="20" value="#{roomController.name}">
                            <f:validateLength minimum="2"/>
                        </h:inputText>
                    </td>
                </tr>
                <tr>
                    <td>Number of seat rows:</td>
                    <td>
                        <h:selectOneMenu class="inputText" value="#{roomController.selectedRow}">
                            <f:selectItems value="#{roomController.rowValues}"/>
                        </h:selectOneMenu>
                    </td>
                </tr>
                <tr>
                    <td>Number of seats per row:</td>
                    <td>
                        <h:selectOneMenu class="inputText" value="#{roomController.selectedSeat}">
                            <f:selectItems value="#{roomController.seatValues}"/>
                        </h:selectOneMenu>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><h:commandButton value="Add Room" class="adminButton"
                                         action="#{roomController.addRoom}"/></td>
                </tr>
            </table>
        </h:form>
    </ui:define>
</ui:composition>
</html>